<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="Generator" content="EditPlus®">
	<meta name="Author" content="">
	<meta name="Keywords" content="">
	<meta name="Description" content="">
	<title>Document</title>
	<script type="text/javascript" src="./js/mico-dc-0.1.js"></script>

	<script>

		// 打开matt服务
		function startMqtt() {
			var host = "api.easylink.io";
			var username = "";
			var password = "";
			var clientID = "clientId-abcdedf";
			var topic = "d64f517c/c8934691813c/#";
			// var topic = "8511d9a2/c89346000106/out.wechat/5560205cdeaa";
			$mico.startMqtt(host,username,password,clientID,topic, function(ret, err) {
				alert("ret = "+ret);
			});			
		}
		
		// 开始接受消息
		function recvMqttMsg() {
			$mico.recvMqttMsg(function(ret, err) {
				alert("topic = "+ret.topic);
				alert("subs = "+ret.subs);
				alert("json subs = "+JSON.stringify(ret.subs));
			});
		}	

		// 发送指令
		function publishCommand() {
			var topic = "d64f517c/c8934691813c/in/write/app1";
			var command = '{"4":true,"5":0, "6":100, "7":100}';
			$mico.publishCommand(topic,command, function(ret, err) {
				alert("subs = "+ret);
			});
		}	

		// 停止接受信息
		function stopRecvMqttMsg() {
			$mico.stopRecvMqttMsg(function(ret, err) {
				alert("subs = "+ret);
			});
		}	

		// 关闭mqtt服务
		function stopMqtt() {
			$mico.stopMqtt(function(ret, err) {
				alert("subs = "+ret);
			});
		}	
	</script>

</head>
<body>
	<br/><br/>
	<input type="button" onclick="startMqtt()" value="打开MQTT"/>
	<br/><br/>
	<input type="button" onclick="recvMqttMsg()" value="接受消息"/>	
	<br/><br/>
	<input type="button" onclick="stopRecvMqttMsg()" value="停止接受消息"/>	
	<br/><br/>
	<input type="button" onclick="stopMqtt()" value="关闭MQTT"/>	
	<br/><br/>
	<input type="button" onclick="publishCommand()" value="发送指令"/>
</body>
</html>
